<?php

/**
 * This is the model class for table "diary".
 *
 * The followings are the available columns in table 'diary':
 * @property string $id
 * @property integer $user_id
 * @property integer $parent_task
 * @property string $rec_date
 * @property integer $prio
 * @property string $comp_date
 * @property integer $comp_type
 * @property string $txt_id
 * @property string $comp_txt_id
 * @property string $task_id
 */
class Diary extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return diary the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'diary';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_id, rec_date, txt_id', 'required'),
			array('user_id, parent_task, prio, comp_type', 'numerical', 'integerOnly'=>true),
			array('comp_date, comp_txt_id', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('diary_id, user_id, parent_task, rec_date, prio, comp_date, comp_type, txt_id, comp_txt_id, task_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'User' => array(self::BELONGS_TO, 'Users', 'user_id'),
			'Text' => array(self::BELONGS_TO, 'Texts', 'txt_id'),
		    'CompText' => array(self::BELONGS_TO, 'Texts', 'comp_txt_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'diary_id' => 'Id',
			'user_id' => 'User',
			'parent_task' => 'Parent Task',
			'rec_date' => 'Дата',
			'prio' => 'Приоритет',
			'comp_date' => 'Дата завершения',
			'comp_type' => 'Comp Type',
			'txt_id' => 'Txt',
			'comp_txt_id' => 'Comp Txt',
			'task_id' => 'Task',
		    'Text.txt' => 'Текст',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('diary_id',$this->id,true);

		$criteria->compare('user_id',$this->user_id);

		$criteria->compare('parent_task',$this->parent_task);

		$criteria->compare('rec_date',$this->rec_date,true);

		$criteria->compare('prio',$this->prio);

		$criteria->compare('comp_date',$this->comp_date,true);

		$criteria->compare('comp_type',$this->comp_type);

		$criteria->compare('txt_id',$this->txt_id,true);

		$criteria->compare('comp_txt_id',$this->comp_txt_id,true);

		$criteria->compare('task_id',$this->task_id,true);

		return new CActiveDataProvider('diary', array(
			'criteria'=>$criteria,
		));
	}
}